<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script type="text/javascript">
        // 使用工厂方法创建对象
        function createPerson(name, age) {
            var obj = new Object();

            obj.name = name;
            obj.age = age;
            obj.sayName = function () {
                console.log(this.name);
            }

            return obj;
        }

        var obj2 = createPerson("zc", 23);
        console.log(obj2);


        // 构造函数
        // 普通函数是直接调用，而构造函数需要使用new关键字来调用

        function Person(name) {
            this.name = name;
        }

        var per = new Person("zc");

        console.log(per);

        console.log(per instanceof Person);

    </script>


</head>

<body>

</body>

</html>